
	Date.prototype.format = function(fmt){ 
		let isS = fmt.endsWith('.S');
	    var o = {
	        "M+" : this.getMonth()+1, //月份
	        "d+" : this.getDate(), //日
	        "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时
	        "H+" : this.getHours(), //小时
	        "m+" : this.getMinutes(), //分
	        "s+" : this.getSeconds(), //秒
	        "q+" : Math.floor((this.getMonth()+3)/3), //季度
	        "S" : this.getMilliseconds() //毫秒
	    };
	    if(/(y+)/.test(fmt))
	        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	    for(var k in o)
	        if(new RegExp("("+ k +")").test(fmt))
	    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
	    if(isS){
			let arr = fmt.split('.');
			while(arr[arr.length - 1].length < 3){
				arr[arr.length - 1] = arr[arr.length - 1]+ "0";
				fmt = fmt + "0";
			}
		}
		return fmt;
	} 

	function downloadImage(name, imgEl) {
	    var image = new Image()
	    // 解决跨域 Canvas 污染问题
	    image.setAttribute('crossOrigin', 'anonymous')
	    image.onload = function () {
	        var canvas = document.createElement('canvas')
	        canvas.width = image.width
	        canvas.height = image.height
	 
	        var context = canvas.getContext('2d')
	        context.drawImage(image, 0, 0, image.width, image.height)
	        var url = canvas.toDataURL('image/png')
	 
	        // 生成一个a元素
	        var a = document.createElement('a')
	        // 创建一个单击事件
	        var event = new MouseEvent('click')
	 
	        // 将a的download属性设置为我们想要下载的图片名称，若name不存在则使用‘下载图片名称’作为默认名称
	        a.download = name || '下载图片名称'
	        // 将生成的URL设置为a.href属性
	        a.href = url
	 
	        // 触发a的单击事件
	        a.dispatchEvent(event)
	    }
	    image.src = imgEl.src
	}
	
	//https://blog.csdn.net/sinat_38349704/article/details/108007633
	//int转hex
	function intTohex(data, len) {
		// console.log(data);
		len = len * 2;
		var retVal = data.toString(16);
		//console.log(retVal);
		if (retVal.length > len) return retVal;
		var length = retVal.length;
		for (var i = 0; i < len - length; i++) {
			retVal = '0' + retVal;
		}
		return retVal;
	} 


	// ArrayBuffer转16进度字符串示例
	function ab2hex(buffer) {
	  const hexArr = Array.prototype.map.call(
	    new Uint8Array(buffer),
	    function (bit) {
	      return (`00${bit.toString(16)}`).slice(-2)
	    }
	  )
	  return hexArr.join(' ')
	}

	//Uint16Array还是Uint8Array需要和后台确认
	function ab2str(buf, isInt16) {
		if(isInt16) return String.fromCharCode.apply(null, new Uint16Array(buf));
		else return String.fromCharCode.apply(null, new Uint8Array(buf));
	}

	function str2ab(str) {
	  var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
	  var bufView = new Uint16Array(buf);
	  for (var i=0, strLen=str.length; i < strLen; i++) {
	    bufView[i] = str.charCodeAt(i);
	  }
	  return buf;
	}



	/**
	 * data:  Data int 
	 * len:  Hex byte length  int 
	 * */
	function int2HexArray(data,len){
		let int = intTohex(data, len)
		var intArr = every2StrToArray(int);
		let byteArr = [];
		for(let j = 0 ;j<intArr.length;j++){
			byteArr.push(parseInt("0x"+intArr[j], 16));
		}
		return byteArr;
	}

	function unionBufferArray(bfArr) {
	  	var tmp = new Uint8Array(bfArr[0].byteLength);
	  	tmp.set(new Uint8Array(bfArr[0]), 0);
		for(let i = 1; i < bfArr.length; i ++){
			var tmp1 =  new Uint8Array(tmp.byteLength + bfArr[i].byteLength);
			  tmp1.set(new Uint8Array(tmp), 0);
			  tmp1.set(new Uint8Array(bfArr[i]), tmp.byteLength);
			  tmp = tmp1;
		}
	  	return tmp;
	};
	
	function bufferToImgUrl(buffer){
		 // Obtain a blob: URL for the image data.
	    var arrayBufferView = new Uint8Array(buffer);
	    var blob = new Blob( [ arrayBufferView ], { type: "image/png" } );
	    var urlCreator = window.URL || window.webkitURL;
	    var imageUrl = urlCreator.createObjectURL( blob );
	    return imageUrl;
	    img_camera.src = imageUrl;
	    downloadImage(result_TAKE_PHOTO.uuid);
	}
   
   	/*
	*fileEl :file input element
	*sliceNum :file slice unit number,if defined, minimum value is 50,
	*/
    function parsefile(fileEl, sliceNum) {  
     	 return new Promise(function (resolve, reject) {
			try {
				var fileObj = fileEl.files[0];       
				var reader = new FileReader();            
				reader.readAsArrayBuffer(fileObj);   
				var max = fileObj.size;
				reader.onload = function () {
					let bytes = new Uint8Array(this.result); 
					let int8Array = []; 
					if(sliceNum && sliceNum > 50){
						let tmpArr = []; 
						for (var i = 0; i < bytes.length; i++) {
							tmpArr.push(bytes[i]);
							if(tmpArr.length == sliceNum || i == bytes.length -1){
								int8Array.push(tmpArr);
								tmpArr = []; 
							}
						} 
					}else{
						for (var i = 0; i < bytes.length; i++) {
							int8Array.push(bytes[i]);
						} 
					}
					resolve(int8Array);
				 } ;
				 
				 reader.onprogress = function (evt) {
					 let progress = evt.loaded/max*100 + '%';
					console.log("onprogress  "+progress);
				 } 
			} catch (error) {
				 reject(error);
			}
        });
 	}


	/*
	* 移除数组中为空（空格，null，等等）的元素
	* @return 数组
	*/
	function removeEmptyOfArray(array){  
	    for(let i = 0 ;i<array.length;i++){  
	       //这里为过滤的值
	        if(array[i] == "\t" ||array[i] == "\n" ||array[i] == "\r" || array[i] == ""  ||array[i] == " " || array[i] == null || typeof(array[i]) == "undefined" || array[i] == '  ' ){  
	            array.splice(i,1);
	            i= i-1;
	        }  
	    }  
	    return array;  
	}

	/*
	* 每俩字符分割，返回数组
	* @return string数组
	*/
	function every2StrToArray(data){  
		let charSep =',';
	    let result = '';
		for (let i = 0;i < data.length; i++ ){
		    result += data[i];
		    if(i % 2 === 1) result += charSep;
		}
		if(result.endsWith(charSep)) result =result.substr(0,result.length-1);
		return result.split(charSep)
	}

	function strToHexCharCode(str) {
	    if(str === "")
	        return "";
	    var hexCharCode = [];
	    hexCharCode.push("0x"); 
	    for(var i = 0; i < str.length; i++) {
	        hexCharCode.push((str.charCodeAt(i)).toString(16));
	    }
	    return hexCharCode.join("");
	}